package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduCourseSelectionDTO;
import com.zenith.edu.po.vo.EduCourseSelectionVO;
import com.zenith.edu.service.EduCourseSelectionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/course-selection")
@Tag(name = "课程选课管理", description = "课程选课管理接口")
public class EduCourseSelectionController {
    
    @Autowired
    private EduCourseSelectionService eduCourseSelectionService;
    
    @SecurePostMapping(value = "/createCourseSelection",roles = {"ADMIN"},permission = "courseSelection:create")
    @Operation(summary = "创建课程选课")
    public Result<EduCourseSelectionVO> createCourseSelection(@RequestBody EduCourseSelectionDTO dto) {
        EduCourseSelectionVO courseSelectionVO = eduCourseSelectionService.createCourseSelection(dto);
        return Result.success(courseSelectionVO);
    }
    
    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取课程选课详情")
    public Result<EduCourseSelectionVO> getCourseSelectionById(@PathVariable Long id) {
        EduCourseSelectionVO courseSelectionVO = eduCourseSelectionService.getCourseSelectionById(id);
        if (courseSelectionVO == null) {
            return Result.fail("课程选课不存在");
        }
        return Result.success(courseSelectionVO);
    }
    
    @SecurePostMapping(value="updateCourseSelection",roles = {"ADMIN"},permission = "courseSelection:update") 
    @Operation(summary = "更新课程选课信息")
    public Result<EduCourseSelectionVO> updateCourseSelection(@RequestBody EduCourseSelectionDTO dto) {
        EduCourseSelectionVO courseSelectionVO = eduCourseSelectionService.updateCourseSelection(dto);
        return Result.success(courseSelectionVO);
    }
    
    @SecurePostMapping(value = "/deleteCourseSelection/{id}",roles = "ADMIN",permission = "courseSelection:delete")
    @Operation(summary = "删除指定课程选课")
    public Result<Void> deleteCourseSelection(@PathVariable Long id) {
        boolean result = eduCourseSelectionService.deleteCourseSelection(id);
        if (!result) {
            return Result.fail("课程选课删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getCourseSelectionList",roles = {"ADMIN"},permission = "courseSelection:read")
    @Operation(summary = "获取课程选课列表")
    public Result<List<EduCourseSelectionVO>> getCourseSelectionList() {
        List<EduCourseSelectionVO> courseSelectionList = eduCourseSelectionService.getCourseSelectionList();
        return Result.success(courseSelectionList);
    }
}